home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / BGUI11c.lha / ARexxClass / arexxdemo.c < prev    next >
C/C++ Source or Header  |  1995-04-30  |  10KB  |  257 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc arexxdemo.c -proto -mi -ms -lbgui -larexxclass.o
  3. quit
  4. */
  5. /*
  6. **             File: arexxdemo.c
  7. **      Description: Simple demonstration of the arexx class.
  8. **        Copyright: (C) Copyright 1994-1995 Jaba Development.
  9. **                   (C) Copyright 1994-1995 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **/
  12.  
  13. #include <libraries/bgui.h>
  14. #include <libraries/bgui_macros.h>
  15. #include <libraries/gadtools.h>
  16.  
  17. #include <dos/dos.h>
  18. #include <dos/datetime.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/bgui.h>
  24. #include <proto/intuition.h>
  25. #include <proto/dos.h>
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. #include "arexxclass.h"
  32.  
  33. /*
  34. **      ARexx class base variable.
  35. **/
  36. Class                           *ARexxClass;
  37.  
  38. /*
  39. **      Protos for the arexx command functions.
  40. **/
  41. VOID rx_Name( REXXARGS *, struct RexxMsg * );
  42. VOID rx_Version( REXXARGS *, struct RexxMsg * );
  43. VOID rx_Author( REXXARGS *, struct RexxMsg * );
  44. VOID rx_Date( REXXARGS *, struct RexxMsg * );
  45.  
  46. /*
  47. **      The following commands are
  48. **      valid for this demo.
  49. **/
  50. REXXCOMMAND Commands[] = {
  51.         "NAME",                 NULL,                   rx_Name,
  52.         "VERSION",              NULL,                   rx_Version,
  53.         "AUTHOR",               NULL,                   rx_Author,
  54.         "DATE",                 "SYSTEM/S",             rx_Date,
  55. };
  56.  
  57. /*
  58. **      NAME
  59. **/
  60. VOID rx_Name( REXXARGS *ra, struct RexxMsg *rxm )
  61. {
  62.         /*
  63.         **      Simply return the program name.
  64.         **/
  65.         ra->ra_Result = "ARexxDemo";
  66. }
  67.  
  68. /*
  69. **      VERSION
  70. **/
  71. VOID rx_Version( REXXARGS *ra, struct RexxMsg *rxm )
  72. {
  73.         /*
  74.         **      Simply return the program version.
  75.         **/
  76.         ra->ra_Result = "1.0";
  77. }
  78.  
  79. /*
  80. **      AUTHOR
  81. **/
  82. VOID rx_Author( REXXARGS *ra, struct RexxMsg *rxm )
  83. {
  84.         /*
  85.         **      Simply return the authors name.
  86.         **/
  87.         ra->ra_Result = "Jan van den Baard";
  88. }
  89.  
  90. /*
  91. **      Buffer for the system date.
  92. **/
  93. UBYTE                   systemDate[ 10 ];
  94.  
  95. /*
  96. **      DATE
  97. **/
  98. VOID rx_Date( REXXARGS *ra, struct RexxMsg *rxm )
  99. {
  100.         struct DateTime                 dt;
  101.  
  102.         /*
  103.         **      SYSTEM switch specified?
  104.         **/
  105.         if ( ! ra->ra_ArgList[ 0 ] )
  106.                 /*
  107.                 **      No. Simply return the compilation date.
  108.                 **/
  109.                 ra->ra_Result = "25-09-94";
  110.         else {
  111.                 /*
  112.                 **      Compute system date.
  113.                 **/
  114.                 DateStamp(( struct DateStamp * )&dt );
  115.                 dt.dat_Format  = FORMAT_CDN;
  116.                 dt.dat_StrDate = systemDate;
  117.                 dt.dat_Flags   = 0;
  118.                 dt.dat_StrDay  = NULL;
  119.                 dt.dat_StrTime = NULL;
  120.                 DateToStr(&dt);
  121.                 /*
  122.                 **      And return it.
  123.                 **/
  124.                 ra->ra_Result = systemDate;
  125.         }
  126. }
  127.  
  128. /*
  129. **      Object ID's.
  130. **/
  131. #define ID_QUIT                 1
  132.  
  133. int main( int argc, char *argv[] )
  134. {
  135.         struct Window           *window;
  136.         Object                  *WO_Window, *GO_Quit, *AO_Rexx;
  137.         ULONG                    signal = 0, rxsig = 0L, rc, sigrec;
  138.         BOOL                     running = TRUE;
  139.  
  140.         /*
  141.         **      Initialize the ARexxClass.
  142.         **/
  143.         if ( ARexxClass = InitARexxClass()) {
  144.                 /*
  145.                 **      Create host object.
  146.                 **/
  147.                 if ( AO_Rexx = NewObject( ARexxClass, NULL, AC_HostName, "RXDEMO", AC_CommandList, Commands, TAG_END )) {
  148.                         /*
  149.                         **      Create the window object.
  150.                         **/
  151.                         WO_Window = WindowObject,
  152.                                 WINDOW_Title,           "ARexx Demo",
  153.                                 WINDOW_SizeGadget,      FALSE,
  154.                                 WINDOW_RMBTrap,         TRUE,
  155.                                 WINDOW_AutoAspect,      TRUE,
  156.                                 WINDOW_MasterGroup,
  157.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  158.                                                 StartMember,
  159.                                                         InfoFixed( NULL,
  160.                                                                    ISEQ_C "This is a small demonstration of\n"
  161.                                                                    "the ARexx BOOPSI class. Please run the\n"
  162.                                                                    ISEQ_B "Demo.rexx" ISEQ_N " script and see\n"
  163.                                                                    "what happens",
  164.                                                                    NULL,
  165.                                                                    4 ),
  166.                                                 EndMember,
  167.                                                 StartMember,
  168.                                                         HGroupObject,
  169.                                                                 VarSpace( 50 ),
  170.                                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  171.                                                                 VarSpace( 50 ),
  172.                                                         EndObject,
  173.                                                 EndMember,
  174.                                         EndObject,
  175.                         EndObject;
  176.  
  177.                         /*
  178.                         **      Object created OK?
  179.                         **/
  180.                         if ( WO_Window ) {
  181.                                 /*
  182.                                 **      Assign a key to the button.
  183.                                 **/
  184.                                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  185.                                         /*
  186.                                         **      try to open the window.
  187.                                         **/
  188.                                         if ( window = WindowOpen( WO_Window )) {
  189.                                                 /*
  190.                                                 **      Obtain wait masks.
  191.                                                 **/
  192.                                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  193.                                                 GetAttr( AC_RexxPortMask, AO_Rexx, &rxsig );
  194.                                                 /*
  195.                                                 **      Event loop...
  196.                                                 **/
  197.                                                 do {
  198.                                                         sigrec = Wait( signal | rxsig );
  199.  
  200.                                                         /*
  201.                                                         **      ARexx event?
  202.                                                         **/
  203.                                                         if ( sigrec & rxsig )
  204.                                                                 DoMethod( AO_Rexx, ACM_HANDLE_EVENT );
  205.  
  206.                                                         /*
  207.                                                         **      Window event?
  208.                                                         **/
  209.                                                         if ( sigrec & signal ) {
  210.                                                                 /*
  211.                                                                 **      Handle events.
  212.                                                                 **/
  213.                                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  214.                                                                         /*
  215.                                                                         **      Evaluate return code.
  216.                                                                         **/
  217.                                                                         switch ( rc ) {
  218.  
  219.                                                                                 case    WMHI_CLOSEWINDOW:
  220.                                                                                 case    ID_QUIT:
  221.                                                                                         running = FALSE;
  222.                                                                                         break;
  223.                                                                         }
  224.                                                                 }
  225.                                                         }
  226.                                                 } while ( running );
  227.                                         } else
  228.                                                 puts ( "Could not open the window" );
  229.                                 } else
  230.                                         puts( "Could not assign gadget keys" );
  231.                                 DisposeObject( WO_Window );
  232.                         } else
  233.                                 puts( "Could not create the window object" );
  234.                         DisposeObject( AO_Rexx );
  235.                 } else
  236.                         puts( "Could not create the ARexx host." );
  237.                 FreeARexxClass( ARexxClass );
  238.         } else
  239.                 puts( "Unable to setup the arexx class" );
  240.  
  241.         return( 0 );
  242. }
  243.  
  244. #ifdef _DCC
  245. int wbmain( struct WBStartup *wbs )
  246. {
  247.         return( main( 0, NULL ));
  248. }
  249. #endif
  250.  
  251. /*
  252.  *      $Log: arexxdemo.c,v $
  253.  * Revision 1.1  1994/09/25  14:31:28  jaba
  254.  * Initial revision
  255.  *
  256.  */
  257.